package 补充.网络编程;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Writer;
import java.net.ServerSocket;
import java.net.Socket;

public class TCP网络程序服务器端 {
    public static void main(String[] args) throws IOException {
        ServerSocket serverSocket = new ServerSocket(9191);
        System.out.println("等待接收数据");
        Socket socket = serverSocket.accept();
        InputStream inputStream = socket.getInputStream();
        byte[] buffer = new byte[1024];
        int len = 0;
        while ((len = inputStream.read(buffer))!=-1){
            System.out.println(new String(buffer,0,len));

        }
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("服务器端已收到".getBytes());
        outputStream.close();
        socket.close();
        serverSocket.close();

    }

}
